#include "compile_run.hpp"
#include "../comm/httplib.h"
#include "../comm/log.hpp"
using namespace ns_compile_run;
using namespace ns_log;
using namespace httplib;

void Usage()
{
    std::cout << "Usage:./test port" << std::endl;
}
int main(int argc,char* argv[])
{
    EnableConsoleLogStrategy();
    if(argc != 2)
    {
        Usage();
        return 0;
    }    
    Server svr;
    svr.Post("/compile_and_run",[](const Request &req,Response &resp){
        //请求中的正文部分就是用户传递的json串内容
        std::string in_json = req.body;
        std::string out_json;
        if(in_json.size())
        {
            CompileRun::Start(in_json,out_json);
            //要传递回去的内容正是out_json
            resp.set_content(out_json,"application/json;charset=utf-8");
            resp.status = 201;
        }
    });
    svr.listen("0.0.0.0",std::stoi(argv[1]));
    return 0;
}